function JCMainLookupSelector(arParams){var _this=this;this.timerId=null;this._currentSearchStr="";this.LAYOUT=null;this.VALUE_CONTAINER=null;this.VISUAL=null;this.SEARCH=null;this.__search_current_row=null;arParams.VISUAL.CONTROL_ID=arParams.CONTROL_ID;this.arParams={AJAX_PAGE:arParams.AJAX_PAGE,CONTROL_ID:arParams.CONTROL_ID,LAYOUT_ID:arParams.LAYOUT_ID,INPUT_NAME:arParams.INPUT_NAME,VISUAL:arParams.VISUAL};this.arParams.PROACTIVE="NONE";if(!!arParams.PROACTIVE)this.arParams.PROACTIVE=arParams.PROACTIVE;this.arParams.PROACTIVE=this.arParams.PROACTIVE.toUpperCase();if(!!arParams.AJAX_PARAMS){this.arParams.AJAX_PARAMS=arParams.AJAX_PARAMS}if(!!arParams.VALUE){this.arParams.VALUE=arParams.VALUE}if(!!arParams.INPUT_NAME_SUSPICIOUS){this.INPUT_SUSPICIOUS=null;this.arParams.INPUT_NAME_SUSPICIOUS=arParams.INPUT_NAME_SUSPICIOUS}this.processSearchStr=function(){var t=_this.arParams.AJAX_PAGE+"?MODE=SEARCH";t+="&search="+encodeURIComponent(_this._currentSearchStr);if(_this.arParams.AJAX_PARAMS){for(var e in _this.arParams.AJAX_PARAMS)t+="&"+e+"="+encodeURIComponent(_this.arParams.AJAX_PARAMS[e])}BX.ajax.get(t,_this.ShowSearchResults)};this.ShowSearchResults=function(data){if(null!=_this.__search_current_row)_this.__search_current_row=null;if(null!=_this.SEARCH)_this.SEARCH.innerHTML="";var DATA=[];if(BX.type.isNotEmptyString(data)){var data_test=BX.parseJSON(data);if(data_test){eval("DATA = "+data)}else{if("''"!=data){if("MESSAGE"==_this.arParams.PROACTIVE||"BXWINDOW"==_this.arParams.PROACTIVE){if("MESSAGE"==_this.arParams.PROACTIVE){alert(data)}else{var obDialog=new BX.CDialog({content:data,draggable:true,resizable:false,buttons:[BX.CDialog.btnClose]});obDialog.Show()}_this.VISUAL.TEXT.value=_this.VISUAL.TEXT.value.replace(_this._currentSearchStr,"");_this._currentSearchStr=""}}}}if(DATA.length>0){if(DATA.length==1&&null!=DATA[0].READY){_this.VISUAL.SetTokenData(_this._currentSearchStr,DATA[0],false);return}if(null==_this.SEARCH){if(!!_this.arParams.VISUAL.SEARCH_POSITION&&"absolute"==_this.arParams.VISUAL.SEARCH_POSITION){_this.SEARCH=BX.GetDocElement().appendChild(document.createElement("DIV"));_this.SEARCH.className="mli-search-results";_this.SEARCH.style.position="absolute";if(!!_this.arParams.VISUAL.SEARCH_ZINDEX){_this.arParams.VISUAL.SEARCH_ZINDEX=parseInt(_this.arParams.VISUAL.SEARCH_ZINDEX);if(!isNaN(_this.arParams.VISUAL.SEARCH_ZINDEX)&&0<_this.arParams.VISUAL.SEARCH_ZINDEX){_this.SEARCH.style.zIndex=_this.arParams.VISUAL.SEARCH_ZINDEX}}}else{_this.SEARCH=_this.LAYOUT.appendChild(document.createElement("DIV"));_this.SEARCH.className="mli-search-results";_this.SEARCH.style.position="absolute"}}var pos;if(!!_this.arParams.VISUAL.SEARCH_POSITION&&"absolute"==_this.arParams.VISUAL.SEARCH_POSITION){pos=BX.pos(_this.VISUAL.TEXT,false)}else{pos=BX.pos(_this.VISUAL.TEXT,true)}_this.SEARCH.style.top=pos.bottom+"px";_this.SEARCH.style.left=pos.left+"px";_this.SEARCH.style.width=pos.right-pos.left-2+"px";for(var i=0;i<DATA.length;i++){var obSearchResult=_this.SEARCH.appendChild(document.createElement("DIV"));obSearchResult.className="mli-search-result";obSearchResult.appendChild(document.createTextNode(DATA[i].NAME+" ["+DATA[i].ID+"]"));obSearchResult.BX_ROW_DATA=DATA[i];obSearchResult.onclick=_this.__search_result_click;obSearchResult.onmouseover=_this.__search_result_over;BX.bind(obSearchResult,"mousedown",function(t){t.stopPropagation()})}_this.SEARCH.style.display="block"}else{_this.__hideSearch()}};this.__search_result_click=function(){_this.VISUAL.SetTokenData(_this._currentSearchStr,this.BX_ROW_DATA);_this.__hideSearch()};this.__search_result_over=function(){if(null!=_this.__search_current_row)_this.__search_current_row.className="mli-search-result";_this.__search_current_row=this;this.className="mli-search-result mli-search-current"};jsUtils.addCustomEvent("onEmpUserSelectorChangeTokenActivity",this.SetTokenInput,null,this);BX.addCustomEvent("onGridClearFilter",BX.delegate(this.ClearValues,this));BX.ready(function(){_this.Init()})}JCMainLookupSelector.prototype.Init=function(){if(!!this.bInit)return;this.bInit=true;var _this=this;this.LAYOUT=document.getElementById(this.arParams.LAYOUT_ID);this.VISUAL=new JCMainLookupSelectorText(this.arParams.VISUAL);this.VISUAL.parent=this;this.VISUAL.onCurrentStringExists=function(t){if(_this._currentSearchStr==t){if(null!=_this.SEARCH&&_this.SEARCH.innerHTML.length>0)_this.SEARCH.style.display="block"}else{if(null!=_this.timerId)clearTimeout(_this.timerId);_this._currentSearchStr=t;_this.processSearchStr()}};this.VISUAL.onCurrentStringChange=function(){if(null!=_this.timerId)clearTimeout(_this.timerId);_this.__hideSearch()};this.VISUAL.onUnidentifiedTokenFound=function(str){var url=_this.arParams.AJAX_PAGE+"?MODE=SEARCH";url+="&search="+encodeURIComponent(str);if(_this.arParams.AJAX_PARAMS){for(var param_name in _this.arParams.AJAX_PARAMS)url+="&"+param_name+"="+encodeURIComponent(_this.arParams.AJAX_PARAMS[param_name])}BX.ajax.get(url,function(data){if(data.length<=0)return;var DATA=[];eval("DATA = "+data);if(DATA.length==1&&DATA[0].READY=="Y")_this.VISUAL.SetTokenData(str,DATA[0],false)})};this.VISUAL.onControlKeyPressed=function(t){if(null!=_this.SEARCH&&_this.SEARCH.style.display=="block"){switch(t){case 27:_this.SEARCH.style.display="none";return false;break;case 40:if(null==_this.__search_current_row)_this.SEARCH.firstChild.onmouseover();else if(null!=_this.__search_current_row.nextSibling)_this.__search_current_row.nextSibling.onmouseover();return false;break;case 38:if(null==_this.__search_current_row)_this.SEARCH.lastChild.onmouseover();else if(null!=_this.__search_current_row.previousSibling)_this.__search_current_row.previousSibling.onmouseover();return false;break;case 13:if(null!=_this.__search_current_row)_this.__search_current_row.onclick();return false;break}}return true};if(null!=this.arParams.INPUT_NAME_SUSPICIOUS){this.VISUAL.onSuspiciousTokensFound=function(t){if(null==_this.INPUT_SUSPICIOUS){_this.INPUT_SUSPICIOUS=document.createElement("INPUT");_this.INPUT_SUSPICIOUS.type="hidden";_this.INPUT_SUSPICIOUS.name=_this.arParams.INPUT_NAME_SUSPICIOUS;_this.VALUE_CONTAINER.appendChild(_this.INPUT_SUSPICIOUS)}_this.INPUT_SUSPICIOUS.value=t.join(";")}}this.__hideSearch=function(){if(null!=_this.SEARCH)_this.SEARCH.style.display="none"};this.__delayedHideSearch=function(){if(null!=_this.SEARCH)setTimeout(_this.__hideSearch,500)};jsUtils.addEvent(this.VISUAL.TEXT,"blur",this.__delayedHideSearch);if(BX("value_container_"+this.arParams["CONTROL_ID"]))this.VALUE_CONTAINER=BX("value_container_"+this.arParams["CONTROL_ID"]);else this.VALUE_CONTAINER=this.LAYOUT.appendChild(document.createElement("DIV"));this.VALUE_CONTAINER.style.display="none";if(null!=this.arParams.VALUE)this.SetValue(this.arParams.VALUE)};JCMainLookupSelector.prototype.Clear=function(){jsUtils.removeCustomEvent("onEmpUserSelectorChangeTokenActivity",this.SetTokenInput);this.VISUAL.onCurrentStringChange=null;this.VISUAL.onCurrentStringExists=null;this.VISUAL.onCurrentTokenExists=null;this.VISUAL.onUnidentifiedTokenFound=null;this.VISUAL.onControlKeyPressed=null;this.VISUAL.onSuspiciousTokensFound=null;jsUtils.removeEvent(this.VISUAL.TEXT,"blur",this.__delayedHideSearch);this.VISUAL.Reset(false,true);this.VISUAL=null;if(null!=this.timerId)clearTimeout(this.timerId);if(null!=this.SEARCH){this.SEARCH.parentNode.removeChild(this.SEARCH);this.SEARCH=null}this._currentSearchStr="";BX.cleanNode(this.LAYOUT,true)};JCMainLookupSelector.prototype.SetTokenInput=function(t,e){if(e.CONTROL_ID!=this.arParams.CONTROL_ID)return;if(null==this.VALUE_CONTAINER)return;if(null==e.TOKEN.DATA||null==e.TOKEN.DATA.ID)return;if(null==e.TOKEN.INPUT){e.TOKEN.INPUT=document.createElement("INPUT");e.TOKEN.INPUT.type="hidden";e.TOKEN.INPUT.name=this.arParams.INPUT_NAME+"[]";e.TOKEN.INPUT.value=e.TOKEN.DATA.ID}if(e.TOKEN.ACTIVE&&null==e.TOKEN.INPUT.parentNode){this.AddInput(e.TOKEN.INPUT);jsUtils.onCustomEvent("onLookupInputChange",{CONTROL_ID:this.arParams.CONTROL_ID,ACTION:"add",DATA:e.TOKEN.DATA})}else if(!e.TOKEN.ACTIVE&&null!=e.TOKEN.INPUT.parentNode){this.DeleteInput(e.TOKEN.INPUT);jsUtils.onCustomEvent("onLookupInputChange",{CONTROL_ID:this.arParams.CONTROL_ID,ACTION:"remove",DATA:e.TOKEN.DATA})}};JCMainLookupSelector.prototype.AddValue=function(arValue){if(typeof arValue!="object"||null==arValue.length||null==arValue[0])arValue=[arValue];var _this=this;for(var i=0;i<arValue.length;i++){if(typeof arValue[i]=="object"){if(null!=arValue[i].ID&&null!=arValue[i].NAME){this.VISUAL.AddTokenData(arValue[i],false)}}else{var val=parseInt(arValue[i]);if(!isNaN(val)){var str="q <q@q> ["+val+"]";var url=this.arParams.AJAX_PAGE+"?MODE=SEARCH";url+="&search="+encodeURIComponent(str);if(this.arParams.AJAX_PARAMS){for(var param_name in this.arParams.AJAX_PARAMS)url+="&"+param_name+"="+encodeURIComponent(this.arParams.AJAX_PARAMS[param_name])}BX.ajax.get(url,function(data){if(data.length<=0)return;var DATA=[];eval("DATA = "+data);if(DATA.length==1&&DATA[0].READY=="Y"){_this.VISUAL.AddTokenData(DATA[0],false)}})}}}};JCMainLookupSelector.prototype.SetValue=function(t){this.VISUAL.Reset(true,false);this.ClearValues();this.AddValue(t)};JCMainLookupSelector.prototype.ClearValues=function(){if(this.VALUE_CONTAINER&&this.VALUE_CONTAINER.childNodes){var t=this.VALUE_CONTAINER.childNodes;for(var e=0;e<t.length;e++){var s=t[e];s.value=""}this.CleanUpValues()}};JCMainLookupSelector.prototype.AddInput=function(t){if(this.VALUE_CONTAINER){this.VALUE_CONTAINER.appendChild(t);this.CleanUpValues()}};JCMainLookupSelector.prototype.DeleteInput=function(t){if(this.VALUE_CONTAINER){t.value="";this.CleanUpValues()}};JCMainLookupSelector.prototype.CleanUpValues=function(t){if(this.VALUE_CONTAINER&&this.VALUE_CONTAINER.childNodes){var e;var s=false;var i=this.VALUE_CONTAINER.childNodes;for(e=0;e<i.length;e++){var r=i[e];if(r.value.length>0)s++}e=0;while(e<i.length){var r=i[e];if(r.value.length==0){if(s>0){this.VALUE_CONTAINER.removeChild(r)}else{e++;s++}}else{e++}}}};function JCMainLookupSelectorText(t){var e=this;this.__split_reg=/([,;\n])/;this.__check_reg=/^(.*?) \[\d+\]/m;this.__check_suspicious=[/^[a-z0-9.\-_]+@[a-z0-9.\-]+$/i,/^(.*?)<[a-z0-9.\-_]+@[a-z0-9.\-]+>$/i,/^(.*?)\[[a-z0-9.\-_]+@[a-z0-9.\-]+\]$/i];this.arParams=t;this.__token_index=0;this.previousCurrentHash="";this.previousCurrentIndex=-1;this.timerId=null;this.isMainUiFilter=this.arParams["MAIN_UI_FILTER"]==="Y";this.isMultiple=this.arParams["MULTIPLE"]==="Y";this.TEXT=document.getElementById(this.arParams.ID);this.TEXT.bx_last_position=0;this.TEXT.bx_focused=false;this.TEXT.style.width="95%";if(this.arParams.MAX_WIDTH)this.TEXT.style.width=this.arParams.MAX_WIDTH+"px";if(this.TEXT.type.toLowerCase()=="textarea")this.TEXT.style.height=this.arParams.MIN_HEIGHT+"px";this.__text_focus=function(){e.TEXT.bx_focused=true;if(e.TEXT.value==e.arParams.START_TEXT){e.TEXT.value=""}};this.__text_blur=function(){e.TEXT.bx_focused=false;if(e.TEXT.value==""){e.TEXT.value=e.arParams.START_TEXT}};this.__text_additional_check=function(){e.TEXT.bx_focused=false;e.__process()};if(this.TEXT.value==""){this.TEXT.value=this.arParams.START_TEXT}jsUtils.addEvent(this.TEXT,"focus",this.__text_focus);jsUtils.addEvent(this.TEXT,"blur",this.__text_blur);jsUtils.addEvent(this.TEXT,"blur",this.__text_additional_check);if(null!=this.TEXT.form){jsUtils.addEvent(this.TEXT.form,"submit",this.__text_focus)}this.arTokens=[];this.arTokensMap={};this.onCurrentStringExists=null;this.onCurrentStringChange=null;this.onCurrentTokenExists=null;this.onUnidentifiedTokenFound=null;this.onControlKeyPressed=null;this.onSuspiciousTokensFound=null;this.__ignore_key=false;this.__pre_process=function(){e.__process()};this.TEXT.onkeydown=function(t){if(null==t)t=window.event;if(null!=e.onControlKeyPressed&&(t.keyCode>=37&&t.keyCode<=40||t.keyCode==27||t.keyCode==13)){if(!e.onControlKeyPressed(t.keyCode)){e.__ignore_key=true;return jsUtils.PreventDefault(t)}}};this.TEXT.onclick=this.TEXT.onkeyup=function(t){if(null==t)t=window.event;if(t.type=="keyup"&&t.keyCode>=16&&t.keyCode<=18)return;if(t.type=="keyup"&&e.__ignore_key){e.__ignore_key=false;return false}if(null!=e.timerId)clearTimeout(e.timerId);e.timerId=setTimeout(e.__pre_process,500)};if(this.TEXT.value.length>0){this.timerId=setTimeout(this.__pre_process,200)}e.AdjustHeight()}JCMainLookupSelectorText.prototype.__split=function(t,e,s){if(Object.prototype.toString.call(e)!=="[object RegExp]"){return t.split(e,s)}var i=/()??/.exec("")[1]===undefined;var r=[];var a=0;var n=(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.sticky?"y":"");e=RegExp(e.source,n+"g");var h,l,o,u;t=t+"";if(!i)h=RegExp("^"+e.source+"$(?!\\s)",n);if(s===undefined||+s<0){s=Infinity}else{s=Math.floor(+s);if(!s)return[]}while(l=e.exec(t)){o=l.index+l[0].length;if(o>a){r.push(t.slice(a,l.index));if(!i&&l.length>1){l[0].replace(h,function(){for(var t=1;t<arguments.length-2;t++)if(arguments[t]===undefined)l[t]=undefined})}if(l.length>1&&l.index<t.length)Array.prototype.push.apply(r,l.slice(1));u=l[0].length;a=o;if(r.length>=s)break}if(e.lastIndex===l.index)e.lastIndex++}if(a===t.length){if(u||!e.test("")){r.push("")}}else{r.push(t.slice(a))}return r.length>s?r.slice(0,s):r};JCMainLookupSelectorText.prototype.__parse=function(t,e,s,i,r){var a=[];var n=[];var h="";if(i&&i.length>0){for(var l=0;l<i.length;l++){if(i[l]){h=jsUtils.trim(i[l].TOKEN);if(h.length){n[n.length]=h;var o=-1;while((o=t.indexOf(h,o+1))>-1){a[a.length]={start:o,end:o+h.length,tok:h,trimmed:jsUtils.trim(h),delim:""}}}}}}if(r&&r.length>0){h=jsUtils.trim(r);if(h.length){n[n.length]=h;o=-1;while((o=t.indexOf(h,o+1))>-1){var u=false;for(var T=0;T<a.length;T++){if(o>=a[T].start&&o<a[T].end){o=a[T].end;u=true;break}}if(!u){a[a.length]={start:o,end:o+h.length,tok:h,trimmed:jsUtils.trim(h),delim:""};break}}}}var _=this.__split(t,e);h="";var A="";var c=0;for(T=0;T<_.length;T++){h=_[T];T++;if(T<_.length)A=_[T];else A="";var E=false;if(h.length){for(var S=0;S<a.length&&!E;S++){if(c>=a[S].start&&c<a[S].end){a[S].delim=A;E=true}}}if(h.length&&!E){if(s.test(h)&&n.length>0){for(l=0;l<n.length;l++){if(h.length>n[l].length&&n[l]==h.substr(h.length-n[l].length)){var f=h.substr(0,h.length-n[l].length);h=h.substr(f.length);while(f&&f.length>0&&f.substr(0,1)==" "){c++;f=f.substr(1)}if(f&&f.length>0){a[a.length]={start:c,end:c+f.length,tok:f,trimmed:jsUtils.trim(f),delim:""};c+=f.length}}}}while(h.length&&h.substr(0,1)==" "){c++;h=h.substr(1)}a[a.length]={start:c,end:c+h.length,tok:h,trimmed:jsUtils.trim(h),delim:A}}c+=h.length+A.length}return a};JCMainLookupSelectorText.prototype.__process=function(){this.__current_token=null;if(this.arParams.START_TEXT.length>0&&this.TEXT.value==this.arParams.START_TEXT||this.TEXT.value==""){this.parent.ClearValues();return}var t=this.__parse(this.TEXT.value,this.__split_reg,this.__check_reg,this.arTokens);var e=this.GetCursorPos();var s;var i=[];for(var r=0;r<t.length;r++){s=e>t[r].start&&e<=t[r].end;var a=jsUtils.trim(t[r].tok);if(a.length>0){if(null!=this.onUnidentifiedTokenFound&&this.__check_reg.test(a)){if(null==this.arTokensMap[this.GetHash(a)])this.onUnidentifiedTokenFound(a)}else{if(s){var n=this.GetHash(a);var h=r;if(null!=this.arTokensMap[this.previousCurrentHash]&&n!=this.previousCurrentHash&&h==this.previousCurrentIndex)this.arTokensMap[this.previousCurrentHash]=null;if(null!=this.onCurrentStringChange&&null!=this.previousCurrentIndex&&this.previousCurrentIndex!=h)this.onCurrentStringChange();if(null!=this.onCurrentStringExists&&null==this.arTokensMap[n])this.onCurrentStringExists(a);if(null!=this.onCurrentTokenExists&&null!=this.arTokensMap[n])this.onCurrentTokenExists(this.arTokensMap[n]);this.previousCurrentHash=n;this.previousCurrentIndex=h}if(null!=this.onSuspiciousTokensFound){for(var l=0;l<this.__check_suspicious.length;l++){if(this.__check_suspicious[l].test(a)){i[i.length]=a;break}}}}}}if(null!=this.onSuspiciousTokensFound)this.onSuspiciousTokensFound(i);this.CheckTokens(t);this.AdjustHeight()};JCMainLookupSelectorText.prototype.Reset=function(t,e){if(null==t)e=false;if(null==e)e=false;for(var s=0;s<this.arTokens.length;s++){if(null==this.arTokens[s])continue;this.arTokensMap[this.arTokens[s].TEXT_HASH]=null;this.arTokens[s]=null}this.arTokens=[];this.arTokensMap={};this.__token_index=0;this.previousCurrentHash="";this.previousCurrentIndex=-1;if(t){this.TEXT.value=this.arParams.START_TEXT}if(e){this.TEXT.onkeydown=this.TEXT.onkeyup=this.TEXT.onclick=null;jsUtils.removeEvent(this.TEXT,"focus",this.__text_focus);jsUtils.removeEvent(this.TEXT,"blur",this.__text_blur);jsUtils.removeEvent(this.TEXT,"blur",this.__text_additional_check);if(null!=this.TEXT.form)jsUtils.removeEvent(this.TEXT.form,"submit",this.__text_focus)}};JCMainLookupSelectorText.prototype.CheckTokens=function(t){if(!t){t=this.__parse(this.TEXT.value,this.__split_reg,this.__check_reg,this.arTokens)}var e=[];for(var s=0;s<t.length;s++){if(t[s].trimmed.length<=0)continue;if(e[t[s].trimmed]!==undefined)continue;e[t[s].trimmed]=s}for(var i=0;i<this.arTokens.length;i++){if(null==this.arTokens[i])continue;var r=jsUtils.trim(this.arTokens[i].TOKEN);this.arTokens[i].SetActive(e[r]!==undefined)}};JCMainLookupSelectorText.prototype.AdjustHeight=function(){if(this.TEXT.scrollHeight>this.TEXT.clientHeight){var t=this.TEXT.offsetHeight-this.TEXT.clientHeight;var e=this.TEXT.scrollHeight+t;if(e>this.arParams.MAX_HEIGHT)e=this.arParams.MAX_HEIGHT;if(this.TEXT.type.toLowerCase()=="textarea")this.TEXT.style.height=e+"px"}};JCMainLookupSelectorText.prototype.AddTokenData=function(t,e){if(this.TEXT.value==this.arParams.START_TEXT)this.TEXT.value="";var s=this.TEXT.scrollTop;if(this.TEXT.type.toLowerCase()=="textarea"){var i=jsUtils.trim(t.NAME+" ["+t.ID+"]");if(this.TEXT.value.indexOf(i)<0){if(this.TEXT.value.length>0&&this.TEXT.value.substr(this.TEXT.value.length-1,1)!="\n")this.TEXT.value+="\n";this.TEXT.value+=i+"\n";this.TEXT.scrollTop=s;this.SetTokenData(i,t,e)}}else{i=jsUtils.trim(t.NAME+" ["+t.ID+"]");if(this.isMultiple&&this.isMainUiFilter){if(this.TEXT.value.indexOf(i)<0){this.TEXT.value+=i+" ";this.SetTokenData(i,t,e)}}else{if(this.TEXT.value.indexOf(i)<0){this.TEXT.value=i;this.SetTokenData(i,t,e)}}}};JCMainLookupSelectorText.prototype.SetTokenData=function(t,e,s){if(null==s)s=true;var i=this.__parse(this.TEXT.value,this.__split_reg,this.__check_reg,this.arTokens,t);var r="";for(var a=0;a<i.length;a++){if(r=="")r=i[a].delim;if(r.length)break}if(r=="")r="\n";for(a=0;a<i.length;a++){var n=jsUtils.trim(i[a].tok);if(n.length<=0)continue;if(t==n){var h=jsUtils.trim(e.NAME+" ["+e.ID+"]");var l="";if(a==i.length||i[a].delim=="")l=r;var o=this.TEXT.scrollTop;var u=this.TEXT.value.substr(0,i[a].start);var T=this.TEXT.value.substr(i[a].end);this.TEXT.value=u+h+l+T;this.TEXT.scrollTop=o;var _=new JCMainLookupSelectorToken({CONTROL_ID:this.arParams.CONTROL_ID,TOKEN:h,INDEX:this.__token_index++,START:i[a].start,FINISH:i[a].start+h.length+l.length,ACTIVE:true,DATA:e});if(null!=this.arTokensMap[_.TEXT_HASH])this.arTokens[this.arTokensMap[_.TEXT_HASH].INDEX]=null;var A=h.length+l.length-i[a].tok.length;this.AdjustTokensPos(i[a].end,A);this.arTokensMap[_.TEXT_HASH]=this.arTokens[_.INDEX]=_;if(s)this.SetCursorPos(_.FINISH);if(null!=this.onCurrentTokenExists)this.onCurrentStringExists(_);this.AdjustHeight();this.__pre_process();return}}this.AddTokenData(e,s)};JCMainLookupSelectorText.prototype.AdjustTokensPos=function(t,e){for(var s=0;s<this.arTokens.length;s++){if(null!=this.arTokens[s]&&this.arTokens[s].ACTIVE&&this.arTokens[s].START>=t){this.arTokens[s].START+=e;this.arTokens[s].FINISH+=e}}};JCMainLookupSelectorText.prototype.SetCursorPos=function(t){if(null!=this.TEXT.selectionStart)this.TEXT.setSelectionRange(t,t);else if(document.selection){try{var e=this.TEXT.createTextRange();e.collapse(true);e.moveEnd("character",t);e.moveStart("character",t);e.select()}catch(t){}}};JCMainLookupSelectorText.prototype.GetCursorPos=function(){try{if(null!=this.TEXT.selectionStart)return this.TEXT.selectionStart;else if(document.selection&&this.TEXT.bx_focused){if(this.TEXT.type.toLowerCase()=="textarea"){var t=document.selection.createRange();var e=t.duplicate();e.moveToElementText(this.TEXT);e.setEndPoint("EndToEnd",t);this.TEXT.bx_last_position=e.text.length}else this.TEXT.bx_last_position=1}return this.TEXT.bx_last_position}catch(t){return 0}};JCMainLookupSelectorText.prototype.GetHash=function(t){var e="";for(var s=0;s<t.length;s++){e+=t.charCodeAt(s).toString(16)}return e};function JCMainLookupSelectorToken(t){var e=this;this.CONTROL_ID=t.CONTROL_ID;this.TOKEN=t.TOKEN;this.INDEX=t.INDEX;this.START=t.START;this.FINISH=t.FINISH;this.DATA=t.DATA;this.SetActive(null==t.ACTIVE?false:t.ACTIVE);this.HASH=this.GetHash(this.INDEX+"$$"+jsUtils.trim(this.TOKEN));this.TEXT_HASH=this.GetHash(jsUtils.trim(this.TOKEN))}JCMainLookupSelectorToken.prototype.SetActive=function(t){this.ACTIVE=!!t;jsUtils.onCustomEvent("onEmpUserSelectorChangeTokenActivity",{CONTROL_ID:this.CONTROL_ID,TOKEN:this})};JCMainLookupSelectorToken.prototype.SetPos=function(t,e){if(null==e)e=t+this.TOKEN.length;this.START=t;this.FINISH=e};JCMainLookupSelectorToken.prototype.GetHash=JCMainLookupSelectorText.prototype.GetHash;